Skip to content

Fix/circular contig closure edge - #415

Open
JeanMainguy wants to merge 2 commits into
devfrom
fix/circular-contig-closure-edge
Open

JeanMainguy wants to merge 2 commits into
devfrom
fix/circular-contig-closure-edge

Conversation

@JeanMainguy

@JeanMainguy JeanMainguy commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Problem

In compute_neighbors_graph, the edge between the last and first genes of a circular
contig skips the rules applied to every other pair of consecutive genes:

  • Fragments: two genes of the same family where one is a fragment are linked anyway.
  • Removed families: contig[0] is used even when its family was removed with
    --remove_high_copy_number.
  • Single-gene circular contigs: the gene is linked to itself.

Fix

  • Move the per-contig logic to add_contig_edges().
  • Close circular contigs on the first kept gene, with the same fragment rule.
  • Skip the closure when only one gene is kept.

Impact

Graph recomputed with ppanggolin graph --force:

Pangenome Gene pairs before Gene pairs after Removed
Chlamydia muridarum (31 genomes) 27,426 27,426 0
E. coli (2,002 genomes) 9,155,155 9,155,103 52 (10 fragment closures + 42 single-gene contigs)

No edge is added; every other gene pair is unchanged.

Tests

New unit tests in tests/unit_tests/graph/test_make_graph.py cover linear and circular
contigs, fragments, tandem copies, removed families and one- and two-gene circular
contigs. All unit tests pass.

Implemented with help from Claude Code.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the circular-contig edge-filtering changes.

No open issues 🎉

What changed in this PR

This PR makes circular-contig closure follow the same filtering rules as other consecutive gene pairs in the neighbors graph.

Changes:

  • Extracts per-contig edge construction into add_contig_edges() with a shared fragment-link check.
  • Closes circular contigs using the first kept gene and skips closure when fewer than two genes remain.
  • Adds unit tests for linear and circular contigs, fragments, tandem copies, removed families, and small contigs.
File Description
tests/​unit_tests/​graph/​test_make_graph.py Adds regression tests for edge construction and circular-contig boundaries.
ppanggolin/​graph/​makeGraph.py Extracts edge-building logic and fixes circular closure filtering and self-links.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants